package com.ruoyi.petition.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.petition.domain.LawyerInfo;
import com.ruoyi.petition.service.ILawyerInfoService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 律师信息Controller
 *
 * @author ZWX
 * @date 2025-07-29
 */
@RestController
@RequestMapping("/petition/lawyerInfo")
@RequiredArgsConstructor
public class LawyerInfoController extends BaseController {
    private final ILawyerInfoService lawyerInfoService;

    /**
     * 查询律师信息列表
     */
    @PreAuthorize("@ss.hasPermi('petition:lawyerInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(LawyerInfo lawyerInfo) {
        startPage();
        List<LawyerInfo> list = lawyerInfoService.selectLawyerInfoList(lawyerInfo);
        return getDataTable(list);
    }

    /**
     * 导出律师信息列表
     */
    @PreAuthorize("@ss.hasPermi('petition:lawyerInfo:export')")
    @Log(title = "律师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LawyerInfo lawyerInfo) {
        List<LawyerInfo> list = lawyerInfoService.selectLawyerInfoList(lawyerInfo);
        ExcelUtil<LawyerInfo> util = new ExcelUtil<LawyerInfo>(LawyerInfo.class);
        util.exportExcel(response, list, "律师信息数据");
    }

    /**
     * 获取律师信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('petition:lawyerInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(lawyerInfoService.selectLawyerInfoById(id));
    }

    /**
     * 新增律师信息
     */
    @PreAuthorize("@ss.hasPermi('petition:lawyerInfo:add')")
    @Log(title = "律师信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LawyerInfo lawyerInfo) {
        return toAjax(lawyerInfoService.insertLawyerInfo(lawyerInfo));
    }

    /**
     * 修改律师信息
     */
    @PreAuthorize("@ss.hasPermi('petition:lawyerInfo:edit')")
    @Log(title = "律师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LawyerInfo lawyerInfo) {
        return toAjax(lawyerInfoService.updateLawyerInfo(lawyerInfo));
    }

    /**
     * 删除律师信息
     */
    @PreAuthorize("@ss.hasPermi('petition:lawyerInfo:remove')")
    @Log(title = "律师信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(lawyerInfoService.deleteLawyerInfoByIds(ids));
    }
}
